package com.itheima.controller;

import com.alibaba.dubbo.config.annotation.Reference;
import com.itheima.entity.Result;
import com.itheima.service.ReportIncomeService;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @Description:
 * @Version: V1.0
 */
@RestController
@RequestMapping("/reportIncome")
public class ReportIncomeController {
    @Reference
    private ReportIncomeService reportIncomeService;

    @RequestMapping("/action")
    public Result action(@RequestBody List<Date> dateValue) {
        Map<String, Object> map = new HashMap<>();
        List<Map<String, Object>> MealIncomes = new ArrayList<>();

        if (dateValue.size() == 0 || dateValue == null) {
            MealIncomes = reportIncomeService.action();
        } else {
            MealIncomes = reportIncomeService.action(dateValue);
        }

        List<String> MealNames = new ArrayList<>();
        for (Map<String, Object> mealIncome : MealIncomes) {
            String name = (String) mealIncome.get("name");
            MealNames.add(name);
        }

        map.put("MealNames", MealNames);
        map.put("MealIncomes", MealIncomes);
        return new Result(true, "上传套餐收入图成功", map);
    }
}
